<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>工位报工</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui-list-swipe.css" />
	<link rel="stylesheet" type="text/css" href="../css/isDialog.css" />
	<link rel="stylesheet" type="text/css" href="../../layui/css/layui.css" media="all" />

	<style type="text/css">

	</style>
</head>

<body>
	<header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
		<a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
			<span class="aui-iconfont aui-icon-left"></span>
		</a>
		<div class="aui-title" id="title">
			工位报工
		</div>
	</header>
	<div id="searchDiv2" class="aui-form" style="margin-top: 2.2rem;">
		<ul class="aui-list aui-form-list" style="font-size: 14px;">
			<li class="aui-list-item">
				<div class="aui-list-item-inner" style="width:100%">
					<div class="aui-list-item-label1" style="margin-top:5px;font-size: 14px;">
						<img src="../image/scanner.png" />
					</div>
					<input class="aui-input" placeholder=" 请扫描器具码 " style="width: 80%;font-size: 18px;" id="huCode2" onkeydown="onkeydownHuCode2()" onclick="getIdSelector();" />
					<i class="aui-input-addon aui-iconfont aui-icon-scan " style="padding-right:10px;font-size: 1.6rem" onclick="toScanner('huCode2');"></i>
				</div>
			</li>
		</ul>
	</div>
	<div class="aui-content aui-margin-b-15">
		<ul class="aui-list aui-form-list">

			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">良品数量</div>
					<div class="aui-list-item-input">
						<input type="number" id="effectiveQty" type="number">
					</div>
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">不良品数量</div>
					<div class="aui-list-item-input">
						<input type="number" id="uneffectiveQty" type="number">
					</div>
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">报废数量</div>
					<div class="aui-list-item-input">
						<input type="number" id="discardQty" type="number">
					</div>
				</div>
			</li>
		</ul>
		<p></p>
		<p></p>
		<div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">保存</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/isDialog.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javssssascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/aui-list-swipe.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script src="../script/swiper.min.js"></script>
<script type="text/javascript">
	apiready = function() {
		// trackId = api.pageParam.trackId;
		$("#huCode2").focus();
		idSelector = "huCode2";
	}

	// 获取光标所在组件的id
	function getIdSelector() {
		var e = event || window.event;
		var el = e.srcElement || e.target;
		idSelector = el.id;
		$("#" + el.id).select();
	}

	function onkeydownHuCode2() {
		if (event.keyCode == 13) {
			var text = document.getElementById("huCode2");
		}
	}

	//扫描
	function toScanner(str) {
		var moduleScanner = api.require('moduleScanner');
		var params = {
			top: 150, //扫描窗口的上边距
			width: 250, //扫描窗口的宽
			height: 250, //扫描窗口的高
			useColor: false, //是否使用自己设定的颜色(startColor和endColor),
			//如果不使用设定的颜色就使用默认的那张网格图
			startColor: '#0F08C8FF', //渐变起始颜色
			endColor: '#7F08C8FF', //渐变结束颜色
			animTime: 2200, //扫描动画时间,单位为毫秒
		};
		moduleScanner.toScannerActivityForResult(params, function(ret, err) {
			var SMequipCode = ret;
			//物料编码
			if (str == 'huCode2') {
				$("#huCode2").val(ret);
			}
		});
	}

	//查询工位是否扫描器具码开关
	function searchChkFlag() {
		var un = localStorage.getItem('un');
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/searchSwitchByCell";
		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		var data = {
			values: {
				un: un,
				cellCode: api.pageParam.cellCode,
			}
		};
		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function(ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//返回成功
				if (myobj.code == "0") {

					chkFlag = myobj.flag

					//失败
				} else if (myobj.code == "1") {
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			}
		});
	}

	function save() {
		var un = localStorage.getItem('un');
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/searchSwitchByCell";
		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		var data = {
			values: {
				un: un,
				cellCode: api.pageParam.cellCode,
			}
		};
		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function(ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//返回成功
				if (myobj.code == "0") {

					//器具码
					var packageNo = $("#huCode2").val();

					//工位扫描器具码开关开启
					if (myobj.flag == 1 || myobj.flag == "1") {
						if (packageNo == null || packageNo == "" || packageNo == undefined) {
							api.toast({
								msg: "请扫描/录入器具码",
								duration: 3000
							});
							return;
						}
					}

					//报工保存
					submit(myobj.flag);

					//失败
				} else if (myobj.code == "1") {
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			}
		});
	}

	//报工保存
	function submit(flag) {
		//器具码
		var packageNo = $("#huCode2").val();
		//良品数
		var effectiveQty = $("#effectiveQty").val();
		//不良品数
		var uneffectiveQty = $("#uneffectiveQty").val();
		//报废数
		var discardQty = $("#discardQty").val();

		if (effectiveQty == null || effectiveQty == "" || effectiveQty < 0) {
			api.toast({
				msg: "请录入良品数",
				duration: 3000
			});
			return;
		}
		api.showProgress({
			title: '保存中...',
			text: '请稍等...',
			duration: 15000,
		});
		var un = localStorage.getItem('un');
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/setPaDaqInfoStateByCell";
		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		var data = {
			values: {
				un: un,
				cellCode: api.pageParam.cellCode,
				trackId: api.pageParam.trackId,
				operateType: '3',
				packageNo: packageNo,
				effectiveQty: effectiveQty == null || effectiveQty == "" ? 0 : effectiveQty,
				uneffectiveQty: uneffectiveQty == null || uneffectiveQty == "" ? 0 : uneffectiveQty,
				discardQty: discardQty == null || discardQty == "" ? 0 : discardQty,
				switchflag: flag,//扫描器具码开关
			}
		};
		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function(ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//返回成功
				if (myobj.code == "0") {

					api.hideProgress();

					api.closeWin({});
					api.execScript({
						name: api.pageParam.name,
						script: 'getTabList()'
					});

					//失败
				} else if (myobj.code == "1") {
					api.hideProgress();
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			}
		});
	}

	//返回按钮
	function closeWin() {
		api.closeWin({});
	}
</script>

</html>
